<template>
	<view class="content">
		<Cupdate v-if="Upgrade" :udatafilePath="udatafilePath" :filePath="filePath" :show="show"></Cupdate>
	</view>
</template>

<script>
	import wx from 'weixin-js-sdk'
	import Cupdate from '@/compontents/Cupdate';
	import {getAppVersion} from '@/api/index.js'
	export default {
		components: {
			Cupdate
		},
		data() {
			return {
				show: null,
				version:"1.0.1",
				Upgrade:false,
				filePath: '',
				udatafilePath: ''
			}
		},
		onLoad() {
			console.log(wx)
			this.getAppVersion()
		},
		methods: {
			//判断版本检查更新
			async getAppVersion(){
				let type = undefined
				let  environment = uni.getSystemInfoSync().platform
				 if(environment == "ios"){
					type = "IOS"
				}else{
					type = "ANDROID"
				}
				let res = await getAppVersion({type});
				if(res.data.version != this.version){
					this.udatafilePath = res.data.updateFilePath;//热更新地址
					this.filePath = res.data.filePath;//强制更新地址
					this.Upgrade = true//有新版本，更新组件展示
					//去掉版本号的点
					var version = res.data.version
					var newstr = version.replace('.','')
					var reg = newstr.replace('.','')
					var a1 = this.version.replace('.','')
					var a2 = a1.replace('.','')
					this.version = a2
					if(!(Number(reg) - Number(this.version) > 2)){
						this.show = true
					}
				}
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
